/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package serverCommunication.StringParser;

import serverCommunication.model.User;

/**
 *
 * @author RodriguesMoises
 */
public class StringToUser {
    public static User parse(String string)
    {
        User user = null;
        if(string.startsWith("|User{") && string.endsWith("}User|"))
        {
            user = new User();
            int indexOfUserId;
            indexOfUserId = string.indexOf("userId=") + "userId=".length();
            String userId = string.substring(indexOfUserId, string.indexOf(",| login="));
            user.setUserId(Integer.parseInt(userId));
            
            int indexOfLogin;
            indexOfLogin = string.indexOf(",| login=") + ",| login=".length();
            String login = string.substring(indexOfLogin, string.indexOf(",| password="));
            user.setLogin(login);
            
            int indexOfPassword;
            indexOfPassword = string.indexOf(",| password=") + ",| password=".length();
            String password = string.substring(indexOfPassword, string.indexOf("}User|"));
            user.setPassword(password);
        }
        return user;
    }
}
